import 'package:aitao_flutter/common_ui/at_switch.dart';
import 'package:aitao_flutter/common_ui/back_nav.dart';
import 'package:aitao_flutter/style/color_style.dart';
import 'package:aitao_flutter/style/edgeInsets_style.dart';
import 'package:aitao_flutter/utils/sp_utils.dart';
import 'package:flutter/material.dart';

class MessageNotificationPage extends StatefulWidget {
  const MessageNotificationPage({super.key});

  @override
  State<MessageNotificationPage> createState() =>
      _MessageNotificationPageState();
}

class _MessageNotificationPageState extends State<MessageNotificationPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BackNavigation(
          title: '新消息通知',
        ),
        body: Column(
          children: [notificationItem(0), notificationItem(1)],
        ));
  }

  Widget notificationItem(int index) {
    return Container(
      padding: EdgeInsetsStyle.customMargin(20, 25, 20, 25),
      child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
        Text(index == 0 ? '声音' : '振动',
            style:
                const TextStyle(color: ColorStyle.color333333, fontSize: 15)),
        CommonSwitchWidget(
            isSelect: getSwitchStatus(index),
            switchCallBack: (state) {
              setSwitchStatus(index, state);
            })
      ]),
    );
  }

  bool getSwitchStatus(int index) {
    if (index == 0) {
      return SpUtil.getSystemVoiceStatus();
    } else {
      return SpUtil.getSystemVibrationStatus();
    }
  }

  void setSwitchStatus(int index, bool state) {
    setState(() {
      if (index == 0) {
        SpUtil.saveSystemVoiceStatus(state);
      } else {
        SpUtil.saveSystemVibrationStatus(state);
      }
    });
  }
}
